// 首先引入Mock
import Mock from "mockjs";

// 设置拦截请求的响应时间
Mock.setup({
  timeout: "200-600",
});

// 读取当前目录下的ts文件
const files = import.meta.glob("./*.ts");
function readFiles() {
  let configArray: Array<object> = [];
  return new Promise(async (resolve) => {
    for (const name in files) {
      // 这里我不知道什么类型
      await files[name]().then((res: any) => {
        configArray.push(res.default);
      });
    }
    resolve(configArray);
  });
}

const arr = await readFiles();

// 注册所有的mock服务
(arr as Array<object>).forEach((item) => {
  for (let [path, target] of Object.entries(item)) {
    let protocol = path.split("|");
    Mock.mock(new RegExp("^" + protocol[1]), protocol[0], target);
  }
});
